using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    public class MRPCustomerTypesService
    {
        ISession session;

        public MRPCustomerTypesService(ISession session)
        {
            this.session = session;
        }
        public MRPCustomerTypesService()
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpcustomertypes(MRPCustomerTypes mrpcustomertypesX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpcustomertypesX);
            tx.Commit();
        }

        public void UpdateMrpcustomertypes(MRPCustomerTypes mrpcustomertypesX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpcustomertypesX);
            tx.Commit();
        }

        public void DeleteMrpcustomertypes(MRPCustomerTypes mrpcustomertypesX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpcustomertypesX);
            tx.Commit();
        }

        public IList<MRPCustomerTypes> GetAllMrpcustomertypes(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPCustomerTypes");
            IList<MRPCustomerTypes> list = query.List<MRPCustomerTypes>();
            if (evict)
            {
                foreach (MRPCustomerTypes s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPCustomerTypes GetAllMrpcustomertypesByID(String id, Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPCustomerTypes as c where c.Customertypecode= :x");
            query.SetString("x", id);
            MRPCustomerTypes s = (MRPCustomerTypes)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPCustomerTypes> GetMrpcustomertypesByQuery(IQuery query, Boolean evict)
        {
            IList<MRPCustomerTypes> list = query.List<MRPCustomerTypes>();
            if (evict)
            {
                foreach (MRPCustomerTypes s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
